<template>
	<view class="page">
		<!-- <view class="flex benben-position-layout flex flex-wrap align-center personalInformation_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub personalInformation_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  personalInformation_fd0_0_c0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">&#xE794;</text>
				</view>
				<text class='personalInformation_fd0_0_c1'>个人中心</text>
				<view class='flex flex-wrap align-center personalInformation_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view> -->
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#FC5B03"></u-loading>
			<view>加载中</view>
		</view>
		<template v-else>
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout personalInformation_flex_1">
				<view class="title_text">基本信息</view>
				<view class='flex flex-wrap align-center justify-between personalInformation_fd1_0'>
					<text class='personalInformation_fd1_0_c0'>头像</text>
					<view class="flex align-center upload position-relative">
			
						<image v-if="user.photo" class="personalInformation_fd1_0_c1_image" mode="aspectFill"
							@tap="uploadImg"
							:src="user.photo"></image>
						<image v-else class="personalInformation_fd1_0_c1_image" mode="aspectFill"
							@tap="uploadImg" :src='STATIC_URL+"237.png"'></image>
						<image class="right_icon" :src='STATIC_URL+"208.png"' mode="aspectFill"></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between personalInformation_fd1_0'>
					<text class='personalInformation_fd1_0_c0'>昵称</text>
					<input class='flex-sub personalInformation_fd1_1_c1' type="text" placeholder="请输入昵称" confirm-type="done" :maxlength="14" placeholder-style="color:rgba(102, 102, 102, 1);font-size:30rpx"
					@blur="saveContact"	v-model="user.nickname" />
					<image class="right_icon" :src='STATIC_URL+"208.png"' mode="aspectFill"></image>
				</view>
				<view class='flex flex-wrap align-center justify-between personalInformation_fd1_0'>
					<text class='personalInformation_fd1_0_c0'>手机号</text>
					<view class="flex flex-wrap align-center">
						<text class='personalInformation_fd1_3_c1'>{{user.phone_no}}</text>
						<image class="right_icon" :src='STATIC_URL+"208.png"' mode="aspectFill"></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between personalInformation_fd1_0'>
					<text class='personalInformation_fd1_0_c0'>紧急联系人</text>
					<view class="flex flex-wrap align-center" @tap.stop="handleJumpDiy"
				data-type="navigateTo" :data-url="`/pages/my/emergencyContact/emergencyContact`">
						<text class='add_text' v-if="!user.jjlxr_name">去添加</text>
						<text class='add_text' v-else>修改</text>
						<image class="right_icon" :src='STATIC_URL+"208.png"' mode="aspectFill"></image>
					</view>
				</view>
			</view>
			<view class="personalInformation_flex_1">
				<view class="title_text">证件信息</view>
				<view class="card_item" v-if="user.id_card_auth == 0 || !user.id_card_auth">
					<image class="left_icon" :src='STATIC_URL+"251.png"' mode=""></image>
					<view class="center_text">
						<view class="center_text_1">身份证</view>
						<view class="center_text_2">上传身份证实名认证</view>
					</view>
					<view class="right_btn" @tap.stop="handleJumpDiy"
				data-type="navigateTo" :data-url="`/pages/my/testExamination/testExamination`">立即上传</view>
				</view>
				<view class="img_list flex align-center justify-between" v-if="user.id_card_auth == 1">
					<view class="img_item">
						<image @tap.stop="previewImage(user.id_card_front)" :src='user.id_card_front' mode="aspectFill"></image>
						<view class="img_tag flex align-center justify-center">身份证人像面</view>
					</view>
					<view class="img_item">
						<image @tap.stop="previewImage(user.id_card_back)" :src='user.id_card_back' mode="aspectFill"></image>
						<view class="img_tag flex align-center justify-center">身份证国徽面</view>
					</view>
				</view>
				<view class="card_item_1" v-if="user.license_auth == 0 || !user.license_auth">
					<image class="left_icon" :src='STATIC_URL+"252.png"' mode=""></image>
					<view class="center_text">
						<view class="center_text_1">驾驶证</view>
						<view class="center_text_2">上传驾驶证以便安全</view>
					</view>
					<view class="right_btn" @tap.stop="handleJumpDiy"
				data-type="navigateTo" :data-url="`/pages/my/testRecord/testRecord`">立即上传</view>
				</view>
				<view class="img_list flex align-center justify-between" v-if="user.license_auth == 1">
					<view class="img_item">
						<image @tap.stop="previewImage(user.driving_img_front)" :src='user.driving_img_front' mode="aspectFill"></image>
						<view class="img_tag flex align-center justify-center">驾驶证正面</view>
					</view>
					<view class="img_item" v-if="user.driving_img_back">
						<image @tap.stop="previewImage(user.driving_img_back)" :src='user.driving_img_back' mode="aspectFill"></image>
						<view class="img_tag flex align-center justify-center">驾驶证副面</view>
					</view>
				</view>
			</view>
			
			<view class="flex align-center justify-between feedback_flex_4">
				<view class='feedback_fd4_0' @tap.stop="getlogOut">退出登录</view>
			</view>
		</template>

	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"pickerDiy1658997072074": false,
				"sexType": [{
					"name": "保密",
					"value": "0",
					"image": ""
				},{
					"name": "男",
					"value": "1",
					"image": ""
				}, {
					"name": "女",
					"value": "2",
					"image": ""
				}],
				"sexLable": "保密",
				"sexValue": "0",
				"user": {
					"invite_code": "",
					"address": "",
					"address_code": "",
					"address_citycode": "",
					"id": "",
					"lastid": "",
					"user_nickname": "",
					"mobile": "",
					"user_name": "",
					"head_img": "",
					"birthday": "",
					"is_finger": "",
					"user_money": "",
					"freeze_money": "",
					"withdrawal_money": "",
					"score": "",
					"empirical": "",
					"invoice_title": "",
					"invoice_company_title": "",
					"total_consumption_money": "",
					"sex": "",
					"create_time": "",
					"phone": "",
					"online": "",
					"_mobile": "",
					"coupon": "",
					"age": "",
					"collection_count": "",
					"browse_count": "",
					"certified": "",
					"invite": []
				},
				"head_img_id": "",
				"isClick": false,
				"disableds": false,
				"isShow": true,
			};
		},
		computed: {
			userInfo: {
				get() {
					return this.$store.state.userInfo
				},
				set() {
					this.$store.commit('updateUserInfo', value)
				},
			}
		},
		watch: {},
		onLoad(options) {
			this.getgetUser();
			uni.$on('save', res => {
				this.getgetUser();
			})
		},
		onUnload() {
			uni.$off('save');
		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//退出登录
			getlogOut() {
				this.$store.commit('logout')
				global.is_close_remind = false;
				uni.reLaunch({
					url: '/pages/tabBar/index/index'
				})
			},
			// 图片上传
			uploadImg() {
				let _this = this;
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.showLoading({
							title: '上传中'
						})
						uni.uploadFile({
							url: global.BASE_URL + global.apiUrls.postUpload, //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'image',
							formData: {
								image: 'image',
								type: 5,
								source: 0,
								user_id: global.userInfo.user_id
							},
							success: (uploadFileRes) => {
								uni.hideLoading();
								console.log(uploadFileRes);
								let result = JSON.parse(uploadFileRes.data);
								if (result.code == 1) {
									_this.user.photo = result.data.photo;
									_this.$message.info('保存成功');
								} else {
									_this.$message.info(result.data.info);
								}
							},
							fail: (err) => {
								console.log(err);
								uni.hideLoading();
								_this.$message.info('图片上传失败，请重试');
							}
						});
					}
				});
			},
			// 保存联系人
			saveContact() {
				if (!this.user.nickname) {
					this.$message.info('请输入昵称');
					return;
				}
				this.$api.post(global.apiUrls.postSaveInformation, {
					nickname: this.user.nickname,
					user_id: this.user.id
				}).then(res => {
					this.$message.info(res.data.info);
					if (res.data.code == 1) {
						this.getgetUser();
					}
				}).catch(err => {
					
				})
			},
			// 预览图片
			previewImage(url) {
				let arr = [];
				arr.push(url);
				uni.previewImage({
					current: 0,
					urls: arr
				})
			},
			//裁剪图片上传
			croppingUploadImage(id, path, obj, obj1, fnName = false) {
				if (this.user.id == 130) {
					return;
				}
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				let itemList = obj1[path] ? ['修改头像', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

				function imageCroppingCuccess() {
					uni.$once('image-cropping-success', (file) => {
						if (!file) return
						new UploadImage([file], {
							complete: (res) => {
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					})
				}
				uni.showActionSheet({
					itemList: itemList,
					success: function(res) {
						if (res.tapIndex == 0 && obj1[path]) {
							uni.navigateTo({
								url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
									obj1[path],
								animationDuration: 0,
							})
							imageCroppingCuccess()
						}
						if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
											res.tempFilePaths[0],
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
						if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
											res.tempFilePaths[0],
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
					},
					fail: function(res) {
						console.log(res.errMsg)
					},
				})
			},
			//获取个人信息
			async getgetUser() {
				//请求方法
				//数据验证

				let userData = await this.$api.get(global.apiUrls.getUser_info, {
					
				});
				this.isShow = false;
				if (userData.data.code != 1) {
					this.$message.info(userData.data.info);
					return
				}
				let userinfo = userData.data;
				this.user = userinfo.data;
				// console.log(this.user);
			},
		}
	};
</script>
<style lang="scss" scoped>
	.img_list {
		margin-top: 24rpx;
		.img_item {
			width: 320rpx;
			height: 180rpx;
			position: relative;
			image {
				width: 100%;
				height: 100%;
				border-radius: 16rpx;
			}
			.img_tag {
				width: 100%;
				height: 50rpx;
				border-radius: 0 0 16rpx 16rpx;
				position: absolute;
				left: 0;
				bottom: 0;
				background: rgba(0, 0, 0, 0.6);
				font-size: 24rpx;
				color: #fff;
			}
		}
	}
	.title_text {
		font-weight: bold;
		font-size: 36rpx;
		color: #111111;
	}
	.card_item {
		width: 100%;
		height: 175rpx;
		background: url(https://speed.zhongchuxing.com/dyimages/249.png) no-repeat;
		background-size: 100% 100%;
		margin: 32rpx 0 0 0;
		padding: 0 42rpx 0 28rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.card_item_1 {
		width: 100%;
		height: 175rpx;
		background: url(https://speed.zhongchuxing.com/dyimages/250.png) no-repeat;
		background-size: 100% 100%;
		margin: 32rpx 0 24rpx 0;
		padding: 0 42rpx 0 28rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.left_icon {
		width: 132rpx;
		height: 132rpx;
		transform: translateY(18rpx);
	}
	.center_text {
		flex: 1;
		.center_text_1 {
			font-weight: bold;
			font-size: 36rpx;
			color: #111111;
		}
		.center_text_2 {
			font-weight: 400;
			font-size: 26rpx;
			color: #666666;
		}
	}
	.right_btn {
		width: 144rpx;
		height: 56rpx;
		background: #1A66FA;
		border-radius: 80rpx;
		font-weight: 500;
		font-size: 26rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.right_icon {
		width: 28rpx;
		height: 28rpx;
	}
	.add_text {
		font-weight: 400;
		font-size: 30rpx;
		color: #1A66FA;
	}
	.save_button {
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background: #1593FF;
		color: #ffffff;
		border-radius: 44rpx;
		position: absolute;
		bottom: 48rpx;
		left: 32rpx;
		font-size: 32rpx;
	}
	.feedback_fd4_0 {
		width: 640rpx;
		border-radius: 80rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #111;
		margin: 0rpx 32rpx 0rpx 32rpx;
		height: 84rpx;
		line-height: 84rpx;
		text-align: center;
		background: #FFFFFF;
		border: 2rpx solid #E7E7E7;
	}
	
	.feedback_flex_4 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		position: fixed;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		display: flex;
		justify-content: center;
		background: #fff;
	}

	.personalInformation_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}

	.personalInformation_picker2_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #BFBFBF;
	}

	.personalInformation_picker2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}

	.personalInformation_picker2_0_c2 {
		color: rgba(44, 143, 255, 1);
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
	}

	.personalInformation_fd1_0 {
		margin-top: 32rpx;
	}

	.personalInformation_fd1_0_c0 {
		font-size: 30rpx;
		font-weight: 400;
		color: #111;
	}

	.personalInformation_fd1_0_c1_image {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
	}

	.personalInformation_fd1_1 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_1_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_1_c1 {
		font-size: 30rpx;
		font-weight: bold;
		color: #111;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_2 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_2_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_2_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_3 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_3_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_3_c1 {
		font-size: 30rpx;
		font-weight: bold;
		color: #111;
	}

	.personalInformation_flex_1 {
		background: #fff;
		border-radius: 16rpx;
		padding: 24rpx 20rpx 24rpx 20rpx;
		margin: 20rpx 24rpx;
	}

	.personalInformation_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.personalInformation_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #111;
		line-height: 36rpx;
	}

	.personalInformation_fd0_0_c1 {
		font-size: 32rpx;
		font-weight: bold;
		color: #111111;
		line-height: 50rpx;
	}

	.personalInformation_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.personalInformation_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #f6f7fb;
		background-size: 100% auto !important;
	}
</style>